package net.bcxuexi.server.model;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;
import java.util.List;

import net.bcxuexi.ports.model.IPort;
import net.bcxuexi.server.stream.AcceptSocket;
import net.bcxuexi.tools.MyLog;

public class ServerSocketModel {
	private String id;//serversocket编号
	/**监听端口*/
	private int port;
	/**
	 * serverSocket类型
	 * control:控制信息serverSocket
	 * data:数据传输
	 * proxy:监控代理端口serverSocket
	 */
	private String type;
	private ServerSocket serverSocket;
	private AcceptSocket acceptSocket;
	/**
	 * 如果type为proxy需要添加iport
	 */
	private List<IPort> iports = new ArrayList<IPort>();
	
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public int getPort() {
		return port;
	}
	public void setPort(int port) {
		this.port = port;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	public ServerSocket getServerSocket() {
		return serverSocket;
	}
	public void setServerSocket(ServerSocket serverSocket) {
		this.serverSocket = serverSocket;
	}
	
	public AcceptSocket getAcceptSocket() {
		return acceptSocket;
	}
	public void setAcceptSocket(AcceptSocket acceptSocket) {
		this.acceptSocket = acceptSocket;
	}
	
	public List<IPort> getIports() {
		return iports;
	}
	public void addIport(IPort iport) {
		this.iports.add(iport);
	}
	public void removeIport(IPort iport) {
		this.iports.remove(iport);
	}
	@Override
	public String toString() {
		String msg = "端口:"+port+",类型:"+type;
		return msg;
	}
	public void close(String msg){
		MyLog.info(msg);
		if(serverSocket!=null&&!serverSocket.isClosed()){
			try {
				serverSocket.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
}
